package com.liang.jiekou.service.impl;


import com.liang.jiekou.mapper.PermissionMapper;
import com.liang.jiekou.service.PermissionService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class PermissionServiceImpl implements PermissionService {

    @Resource
    PermissionMapper permissionMapper;

    //领料单的新增+审核权限
    @Override
    public String selectMOCTCPermission(String MF001) {

        boolean hasMOCI03 = false;

        for (String quanxian : permissionMapper.selectprogram(MF001)) {
            System.out.println(quanxian);
            quanxian.trim();
            if (quanxian.equals("MOCI03")) {
                hasMOCI03 = true;
                break;
            }
        }

    if(hasMOCI03){
        if(permissionMapper.selectGroupPermissions(MF001)==null||permissionMapper.selectGroupPermissions(MF001).equals("N")){
            if(permissionMapper.selectSuUserPermissions(MF001)==null||permissionMapper.selectSuUserPermissions(MF001).equals("N")){
                if(permissionMapper.selectUserPermissions(MF001).substring(8,9).equals("Y")){
                    if(permissionMapper.selectUserPermissions(MF001).substring(3,4).equals("Y")){
                        return "200";
                    }
                }
                return null;
            }
        }
    }
        return "200";
    }


    //入库单的新增+审核权限
    @Override
    public String selectMOCTFPermission(String MF001) {
        boolean hasMOCI05 = false;
        System.out.println(MF001);
        for (String quanxian : permissionMapper.selectprogram(MF001)) {
            System.out.println(quanxian);
            quanxian.trim();
            if (quanxian.equals("MOCI05")) {
                hasMOCI05 = true;
                System.out.println("-----------------------------------------------");
                break;
            }
        }

        if(hasMOCI05){
            if(permissionMapper.selectGroupPermissions(MF001)==null||permissionMapper.selectGroupPermissions(MF001).equals("N")){
                if(permissionMapper.selectSuUserPermissions(MF001)==null||permissionMapper.selectSuUserPermissions(MF001).equals("N")){
                    if(permissionMapper.selectUserPermissions(MF001).substring(8,9).equals("Y")){
                        if(permissionMapper.selectUserPermissions(MF001).substring(3,4).equals("Y")){
                            return "200";
                        }
                    }
                    return null;
                }
            }
        }
        return "200";
    }



    //领料单的撤销审核+删除权限
    @Override
    public String deleteMOCTCPermission(String MF001) {
        boolean hasMOCI03 = false;

        for (String quanxian : permissionMapper.selectprogram(MF001)) {
            System.out.println(quanxian);
            quanxian.trim();
            if (quanxian.equals("MOCI03")) {
                hasMOCI03 = true;
                break;
            }
        }

        if(hasMOCI03){
            if(permissionMapper.selectGroupPermissions(MF001)==null||permissionMapper.selectGroupPermissions(MF001).equals("N")){
                if(permissionMapper.selectSuUserPermissions(MF001)==null||permissionMapper.selectSuUserPermissions(MF001).equals("N")){
                    if(permissionMapper.selectUserPermissions(MF001).substring(4,5).equals("Y")){
                        if(permissionMapper.selectUserPermissions(MF001).substring(2,3).equals("Y")){
                            return "200";
                        }
                    }
                    return null;
                }
            }
        }
        return "200";
    }


    //入库单的撤销审核+删除权限
    @Override
    public String deleteMOCTFPermission(String MF001) {
        boolean hasMOCI05 = false;

        for (String quanxian : permissionMapper.selectprogram(MF001)) {
            System.out.println(quanxian);
           String a = quanxian.trim();
            if (a.equals("MOCI05")) {
                hasMOCI05 = true;
                break;
            }
        }

        if(hasMOCI05){
            if(permissionMapper.selectGroupPermissions(MF001)==null||permissionMapper.selectGroupPermissions(MF001).equals("N")){
                if(permissionMapper.selectSuUserPermissions(MF001)==null||permissionMapper.selectSuUserPermissions(MF001).equals("N")){
                    if(permissionMapper.selectUserPermissions(MF001).substring(4,5).equals("Y")){
//                        System.out.println(permissionMapper.selectUserPermissions(MF001));
//                        System.out.println(permissionMapper.selectUserPermissions(MF001).substring(2,3));
                        if(permissionMapper.selectUserPermissions(MF001).substring(2,3).equals("Y")){
                            return "200";
                        }
                    }
                    return null;
                }
            }
        }
        return "200";
    }
}

